package com.congwulin.wechat.controller;

import com.congwulin.wechat.entity.WeChatMessage;
import com.congwulin.wechat.service.WeChatMessageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "message")
public class MessageConfirmController {
    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private WeChatMessageService service;

    @RequestMapping(value = "/confirm",method = RequestMethod.GET)
    public@ResponseBody
    String confirm_get(WeChatMessage message){
//        System.out.println(message.getSignature());
//        System.out.println(message.getNonce());
//        System.out.println(message.getTimestamp());
//        System.out.println(message.getEchostr());
        return service.checkSignature(message);
    }

    @RequestMapping(value = "/confirm",method = RequestMethod.POST)
    public@ResponseBody
    String confirm_post(@RequestBody String message){
//        System.out.println(message.getAppId());
//        System.out.println(message.getContent());
//        System.out.println(message.getCreateTime());
//        System.out.println(message.getEvent());
//        System.out.println(message.getFromUserName());
//        System.out.println(message.getToUserName());
//        System.out.println(message.getMediaId());
//        System.out.println(message.getMsgId());
//        System.out.println(message.getMsgType());
//        System.out.println(message.getPagePath());
//        System.out.println(message.getPicUrl());
//        System.out.println(message.getTitle());
//        System.out.println(message.getThumbUrl());
//        System.out.println(message.getSessionFrom());
//        System.out.println(message.getThumbMediaId());
        System.out.println(message);
        return "success";
    }
}
